import axios from "axios";
import {
  postCardinfo
} from "../../api/patient";
export default {
  namespaced: true,
  state: {
    doctorinfo: [],
    // 时间
    day: "",
    // 挂号信息
    order: {},
    // 价格
    price: null,
    // 就诊人信息
    visitor: {},

    // 所有就诊人
    visitorList: [],

    //挂号医生的id，
    doctorid: '',

    //号数
    num: ''
  },
  mutations: {
    setdoctorinfo(state, value) {
      state.doctorinfo = value;
    },
    setday(state, value) {
      console.log(value);
      state.day = value;
    },
    // 挂号价格
    registrationPrice(state, value) {
      console.log("----价格----", value);
      state.price = value;
    },
    orderDetails(state, value) {
      console.log("----订单：----", value);
      state.order = value;
    },

    // 就诊人
    visitorInformation(state, value) {
      console.log("----就诊人----", value);
      state.visitor = value;
    },

    // 就诊人列表
    visitorListData(state, value) {
      console.log("----就诊人列表----", value);
      state.visitorList = value;
    },

    //医生号数减少
    doctorreduce(state, value) {
      state.doctorid = value;
    },

    doctornum(state, value) {
      state.num = value;
    }
  },
  actions: {
    async getdoctorinfo(context) {
      try {
        let arr = [];
        const res = await axios.post("/api/cate/select");
        res.data.datas.map((item) => {
          if (item.cate != 4) {
            arr.push(item);
          }
        });
        context.commit("setdoctorinfo", arr);
      } catch (error) {
        console.log(error);
      }
    },

    // 获取所有就诊卡
    async cardinfoData(context) {
      const {
        data
      } = await postCardinfo();
      // console.log("---就诊卡数据---", data.data[0]);
      context.commit("visitorInformation", data.data[0]);
      context.commit("visitorListData", data.data);
    },
  },
};